/**
 * @description:
 * @author: 梅雄
 * @createDate: 2021/12/26
 * @version: 1.0
 * @status: done
 */
package com.xhwl.centiotdata.suppliersystem.yidea;

import com.xhwl.centiotdata.pojo.dto.eesd.EesdConfigDTO;
import com.xhwl.centiotdata.pojo.enums.eesd.EesdMethodEnum;
import com.xhwl.centiotdata.service.integrateconfig.EESDIntegrationConfig;
import com.xhwl.common.dto.cent.eesd.EnvDataReqDTO;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.utils.ChkUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 望美制造 - 资产管理
 * mx
 */
@RestController
public class AssetsHandler {

    @Autowired
    private EESDIntegrationConfig eesdIntegrationConfig;

    @Autowired
    AssetsHandlerUtil assetsHandlerUtil;

    /**
     * 资产列表
     */
    @PostMapping(value = "/wmzz/assets/list")
    public ResultJson pullAssets(@RequestPart(value = "envDataReqDTO") EnvDataReqDTO envDataReqDTO) {
        //拉取配置,进行鉴权,获取资产管理列表
        List<EesdConfigDTO> integrationConfig = eesdIntegrationConfig.getIntegrationConfig(EesdMethodEnum.WMZZ.getId());
        if (ChkUtil.isNull(integrationConfig)) {
            return ResultJson.fail("配置无法获取");
        }
        EesdConfigDTO eesdConfigDTO = integrationConfig.get(0);
        EesdConfigDTO.Assets assets = eesdConfigDTO.getAssets();
        return ResultJson.success(assetsHandlerUtil.getAssets(assets, envDataReqDTO));
    }

    /**
     * 维修列表
     */
    @PostMapping(value = "/wmzz/assets/repair")
    public ResultJson receipt(@RequestPart(value = "envDataReqDTO") EnvDataReqDTO envDataReqDTO) {
        //拉取配置,进行鉴权,获取资产管理维修列表
        List<EesdConfigDTO> integrationConfig = eesdIntegrationConfig.getIntegrationConfig(EesdMethodEnum.WMZZ.getId());
        if (ChkUtil.isNull(integrationConfig)) {
            return ResultJson.fail("配置无法获取");
        }
        EesdConfigDTO eesdConfigDTO = integrationConfig.get(0);
        EesdConfigDTO.Assets assets = eesdConfigDTO.getAssets();
        return ResultJson.success(assetsHandlerUtil.getRepair(assets, envDataReqDTO));
    }
}
